<!-- 
	查看 消缺 任务 
 -->
<template>
	<div>
		<div class="container">
			<div class="boxDiv">
				<div>
					<table class="table table-bordered center " style="line-height: 35px;">
						<tbody>
							<tr>
								<td>任务编码</td>
								<td>
									<span v-text="InfoObj.solvetaskcode"></span>
								</td>
								<td>任务名称</td>
								<td>
									<span v-text="InfoObj.solvetaskname"></span>
								</td>
							</tr>
							<tr>
								<td>任务状态</td>
								<td>
									<span v-text="InfoObj.taskstatusname"></span>
								</td>
								<td>任务单据</td>
								<td>
									<span v-text="InfoObj.workdoctypename"></span>
								</td>
							</tr>
							<tr>
								<td>任务下发人</td>
								<td>
									<span v-text="InfoObj.issuedbyname"></span>
								</td>
								<td>任务下发时间</td>
								<td>
									<span v-text="InfoObj.issuedtime"></span>
								</td>
							</tr>
							<tr>
								<td>任务负责人</td>
								<td>
									<span v-text="InfoObj.taskmanagername"></span>
								</td>
								<td>任务描述</td>
								<td>
									<span v-text="InfoObj.taskdesc"></span>
								</td>
							</tr>
							<tr>
								<td>消缺员</td>
								<td>
									<span></span>
								</td>
								<td>任务完成时间</td>
								<td>
									<span v-text="InfoObj.finishtime"></span>
								</td>
							</tr>
							<tr style="line-height: 80px;">
								<td>负责人审查意见</td>
								<td v-if="this.Audit!='' && this.Audit!=null">
									<textarea style="width: 100%;" v-model="InfoObj.managersuggestion"
										v-text="InfoObj.managersuggestion"></textarea>
								</td>
								<td v-else>
									<span v-text="InfoObj.managersuggestion"></span>
								</td>
								<td>完成情况描述</td>
								<td v-if="this.execute!='' && this.execute!=null">
									<textarea v-model="InfoObj.taskfinishdesc" v-text="InfoObj.taskfinishdesc" cols="25"
										rows="1"></textarea>
								</td>
								<td v-else>
									<span v-text="InfoObj.taskfinishdesc">无</span>
								</td>
							</tr>
							<tr style="line-height: 80px;">
								<td>下发人审查意见</td>
								<td v-if="this.Audit!='' && this.Audit!=null">
									<textarea style="width: 100%;" v-model="InfoObj.issuedsuggestion"
										v-text="InfoObj.issuedsuggestion"></textarea>
								</td>
								<td v-else>
									<span v-text="InfoObj.issuedsuggestion"></span>
								</td>
								<td>审核是否通过</td>
								<td v-if="this.Audit!='' && this.Audit!=null">
									<select v-model="selectedLineId" @change="onLineSelected">
										<option value="-1" selected>--请选择--</option>
										<option v-for="item in AuditList" :value="item.configvalueid" :key="item.id">
											{{ item.configvaluename }}</option>
									</select>
								</td>
								<td v-else>
									<span v-text="InfoObj.taskstatusname"></span>
								</td>
							</tr>
						</tbody>

					</table>
				</div>
				<div>
					<h6>缺陷信息列表</h6>
					<table class="table table-striped table-hover table-bordered center">
						<thead>
							<tr>
								<td v-text="'线路编号'"></td>
								<td v-text="'杆塔编号'"></td>
								<td v-text="'缺陷等级'"></td>
								<td v-text="'缺陷类型'"></td>
								<td v-text="'发现人'"></td>
								<td v-text="'缺陷描述'"></td>
								<td v-text="'发现时间'"></td>
							</tr>
						</thead>
						<tbody v-if="listInTaDe.length > 0" v-for="item in listInTaDe" :key="item.id">
							<tr v-for="i in item">

								<td>{{ i.linecode }}</td>
								<td>{{ i.polecode }}</td>
								<td>{{ i.buglevelname }}</td>
								<td>{{ i.bugtypename }}</td>
								<td>{{ i.discoverername }}</td>
								<td>{{ i.bugdesc }}</td>
								<td>{{ i.discovertime }}</td>
							</tr>
						</tbody>

						<tbody v-else>
							<tr>
								<td colspan="7">暂无数据!!!</td>
							</tr>

						</tbody>

					</table>
				</div>
				<div>
					<h6>工作间断延期记载</h6>
					<textarea v-if="this.execute!='' && this.execute!=null" style="width: 100%;"
						v-model="InfoObj.tasknotes" v-text="InfoObj.tasknotes" cols="30" rows="5"></textarea>
					<span v-else
						v-text="InfoObj.tasknotes=='' || InfoObj.tasknotes==null? '无':InfoObj.tasknotes">无</span>
				</div>
				<div>
					<h6>工作终结报告</h6>
					<textarea v-if="this.execute!='' && this.execute!=null" style="width: 100%;"
						v-model="InfoObj.taskfinishreport" v-text="InfoObj.taskfinishreport" cols="30"
						rows="5"></textarea>
					<span v-else
						v-text="InfoObj.taskfinishreport=='' || InfoObj.taskfinishreport==null? '无':InfoObj.taskfinishreport ">无</span>
				</div>


			</div>
			<div>
				<button type="button" class="btn btn-outline-primary"
					v-if="this.Audit!='' && this.Audit!=null || this.execute!='' && this.execute!=null"
					@click="save">保存</button>
				<button type="button" class="btn btn-outline-primary" @click="$router.go(-1)">返回</button>
			</div>
		</div>

	</div>

	</div>
</template>

<script>
	import {
		queryByObjInTaDeList,
		updatepsSolvetaskMain,
		queryByAudit,
		queryByListl,
		queryIntaDeByObj,
		updatePstaDeObj
	} from '../../config/request.js'
	export default {
		data() {
			return {
				InfoObj: {
					taskstatus: '-1',
				}, // 接收的对象
				selectedLineId: "-1", // 选择的下拉框的id
				listInTaDe: [], //  巡检任务子表对象
				execute: '', // 执行录入的情况
				AuditList: '', // 审核 下拉对象
				Audit: '', // 审核
			}
		},
		methods: {
			load() {
				/* queryByObjInTaDeList(this.InfoObj.inspectiontaskdelid).then(json => {
					this.listInTaDe = json.data.queryByObjInTaDeList
				}) */
				queryByListl(this.InfoObj.solvetaskcode).then(json => {
					if (Object.keys(json.data.objList).length > 0) {
						json.data.objList.forEach(item => {

							queryIntaDeByObj(item.inspectiontaskdelid).then(json => {
								console.log(JSON.stringify(json.data.queryIntaDeByObj) + "111")
								this.listInTaDe.push(json.data.queryIntaDeByObj)
							})

						})

						this.listSode = true;
					}

				})



				// 查询审查状态
				queryByAudit().then(json => {
					this.AuditList = json.data.queryByAudit

				})

			},
			save() {
				if (this.execute != '' && this.execute != null) {
					// 执行录入 或 驳回修改

					this.InfoObj.taskstatus = 4
					this.InfoObj.taskstatusname = '已完成'
					// 修改 消缺 任务
					updatepsSolvetaskMain(this.InfoObj).then(json => {
						alert(json.message)

					})
				} else {
					// 审查操作

					// 修改 消缺 任务
					updatepsSolvetaskMain(this.InfoObj).then(json => {
						alert(json.message)
						
						
					})
					if(this.InfoObj.taskstatusname=='审查通过'){
						
						this.listInTaDe.forEach(item=>{
							console.log(item)
							item[0].issolve=1
							
							updatePstaDeObj(item[0]).then(json=>{
								alert(json.message)
							})
							
						})
						
					}





				}

			},
			onLineSelected() {
				// 找到选中项在 AuditList 中的索引
				const selectedIndex = this.AuditList.findIndex(item => item.configvalueid === this.selectedLineId);
				// 将选中项的对象赋值给 InfoObj

				this.InfoObj.taskstatus = this.AuditList[selectedIndex].configvalueid
				this.InfoObj.taskstatusname = this.AuditList[selectedIndex].configvaluename
			}
		},
		mounted() {
			this.load()
		},
		created() {
			// 接收参数
			this.InfoObj = this.$route.query.obj;


			// 执行录入的情况下 和 驳回后的修改
			this.execute = this.$route.query.execute

			// 审查
			this.Audit = this.$route.query.Audit

		}
	}
</script>

<style lang="less" scoped>
	.container {
		height: 100%;
		background-color: #F2F2F2;
		border-radius: 5px;
		padding: 20px;
	}

	.boxDiv {
		background-color: white;
		height: 100%;
		border: 1px solid black;
		margin: 30px;
		padding: 30px;
		/* display: flex; */
		justify-content: center;
		align-items: flex-start;

		div:nth-of-type(1) {
			margin: 0px 20px 120px 20px;
			font-size: 12px;
		}

		div:nth-of-type(2) {
			margin: 100px 20px 120px 20px;
		}

		div:nth-of-type(3) {
			margin: 100px 20px 120px 20px;
		}

		div:nth-of-type(4) {
			margin: 100px 20px 120px 20px;
		}
	}

	.container div label {
		font-size: 18px;
		margin-right: 10px;
		/* 例如，将右边距设置为 10 像素 */
	}

	.container div span {
		font-family: 宋体;
	}
</style>